﻿#include "stdafx.h"
#include "S_MonitorTreeManager.h"
#include "S_MonitorDataContainer.h"
#include "S_MonitorWindowManager.h"

#include "Source/ModelingPreModule/S_ModelingPre_InteractiveManager.h"
#include "Source/MainModule/Global/S_FloatingTextBlock.h"
#include "Source/Utils/Manager/IconOpacityManager/S_IconOpacityManager.h"
#include "Source/Utils/Operater/TreeItemExpander/P_TreeItemExpender.h"


/*
-----==========================================================-----
		类：		场强探头模块 - 树节点管理.h
		作者：		drill_up
		所属模块：	场强探头模块
		功能：		此类定义该模块所使用的树节点。
					（详细见cpp）
-----==========================================================-----
*/

S_MonitorTreeManager::S_MonitorTreeManager() {

	// > 数据变化信号
	connect(S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::containerDataAdded, this, &S_MonitorTreeManager::containerDataAdded);
	connect(S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::containerDataModifyed, this, &S_MonitorTreeManager::containerDataModifyed);
	connect(S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::containerDataDeleted, this, &S_MonitorTreeManager::containerDataDeleted);
	connect(S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::containerGlobalDataModifyed, this, &S_MonitorTreeManager::containerGlobalDataModifyed);
	connect(S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::containerDataAllReloaded, this, &S_MonitorTreeManager::containerDataAllReloaded);

	// > 数据模型的隐藏
	connect(S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::signal_VisibleChanged_Probe, this, &S_MonitorTreeManager::visibleChanged_Probes);
	connect(S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::signal_VisibleChanged_VoltageMonitor, this, &S_MonitorTreeManager::visibleChanged_VoltageMonitor);
	connect(S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::signal_VisibleChanged_CurrentMonitor, this, &S_MonitorTreeManager::visibleChanged_CurrentMonitor);
}
S_MonitorTreeManager::~S_MonitorTreeManager() {
}

/* --------------------------------------------------------------
---------- 单例
*/
S_MonitorTreeManager* S_MonitorTreeManager::cur_manager = NULL;
S_MonitorTreeManager* S_MonitorTreeManager::getInstance() {
	if (cur_manager == NULL) {
		cur_manager = new S_MonitorTreeManager();
	}
	return cur_manager;
}

/*-----------------------------------
		树根（场监视器） - 树根初始化
*/
void S_MonitorTreeManager::initRoot_FieldMonitor(QTreeWidget* treeWidget) {

	// > 树根设置
	this->m_root_FieldMonitor = new QTreeWidgetItem(treeWidget);
	this->m_root_FieldMonitor->setText(0, tr("Field Monitor"));
	this->m_root_FieldMonitor->setIcon(0, QIcon(":/others" + QRC_IconPath + "/others/DirSource.png"));
	this->m_root_FieldMonitor->setExpanded(false);
	treeWidget->insertTopLevelItem(0, this->m_root_FieldMonitor);
}
/*-----------------------------------
		树根（场监视器） - 获取树根
*/
QTreeWidgetItem* S_MonitorTreeManager::getRoot_FieldMonitor() {
	return this->m_root_FieldMonitor;
}
/*-----------------------------------
		树根（场监视器） - 刷新树根
*/
void S_MonitorTreeManager::refreshRoot_FieldMonitor() {
	this->clearBranch_FieldMonitor();

	// > 树根
	this->m_root_FieldMonitor->setText(0, tr("Field Monitor"));

	// > 树节点
	QList<C_FieldMonitor> port_list = S_MonitorDataContainer::getInstance()->getDataFieldMonitorList();
	for (int i = 0; i < port_list.count(); i++) {
		C_FieldMonitor port = port_list.at(i);
		QTreeWidgetItem* item = new QTreeWidgetItem(this->m_root_FieldMonitor);
		item->setData(0, Qt::UserRole, port.getId());					//（放置ID）
		item->setData(0, Qt::UserRole + 1, port.get__CLASS_NAME__());	//（放置数据类型）
		item->setText(0, port.getName());
		item->setIcon(0, QIcon(":/sim" + QRC_IconPath + "/sim/FieldMonitor.png"));
		this->m_item_FieldMonitor.append(item);
	}
}
/*-----------------------------------
		树根（场监视器） - 清空树根
*/
void S_MonitorTreeManager::clearRoot_FieldMonitor() {
	//（目前树根下没有 重要树枝，直接全清）

	this->clearBranch_FieldMonitor();
}
/*-----------------------------------
		树根（场监视器） - 清空树枝
*/
void S_MonitorTreeManager::clearBranch_FieldMonitor() {
	this->m_root_FieldMonitor->takeChildren();
	this->m_item_FieldMonitor.clear();
}
/*-----------------------------------
		树根（场监视器） - 展开树根
*/
void S_MonitorTreeManager::setRootExpandAll_FieldMonitor() {
	P_TreeItemExpender p;
	p.expandAll(this->m_root_FieldMonitor);
}
/*-----------------------------------
		树根（场监视器） - 折叠树根
*/
void S_MonitorTreeManager::setRootCollapseAll_FieldMonitor() {
	P_TreeItemExpender p;
	p.collapseAll(this->m_root_FieldMonitor);
}

/*-----------------------------------
		树节点事件（场监视器） - 失去焦点时
*/
void S_MonitorTreeManager::itemFocusOut_FieldMonitor(QList<QTreeWidgetItem*> item_list) {

	// > 清空白框描述
	//	（在 S_SoftwareAreaTreeManager 中控制，此处不管）
}

/*-----------------------------------
		树节点事件（场监视器） - 单击操作
*/
void S_MonitorTreeManager::itemClicked_FieldMonitor(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.first();

	//（无）
}
/*-----------------------------------
		树节点事件（场监视器） - 改变操作
*/
void S_MonitorTreeManager::itemSelectionChanged_FieldMonitor(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.last();

	// > 左键树根
	if (this->m_root_FieldMonitor == last_item) {
		S_FloatingTextBlock::getInstance()->hideBlock();
		return;
	}

	// > 左键树节点
	QString id = last_item->data(0, Qt::UserRole).toString();
	QString class_name = last_item->data(0, Qt::UserRole + 1).toString();
	if (item_list.count() == 1){
		if (class_name == "C_FieldMonitor"){

			// > 白框描述
			C_FieldMonitor c_data = S_MonitorDataContainer::getInstance()->getDataFieldMonitorById(id);
			if (c_data.isNull()){
				S_FloatingTextBlock::getInstance()->hideBlock();
				return;
			}
			S_FloatingTextBlock::getInstance()->setText(c_data.getName(), c_data.getAttributesDesc());
			S_FloatingTextBlock::getInstance()->showBlock();
		}
	}
}
/*-----------------------------------
		树节点事件（场监视器） - 双击操作
*/
void S_MonitorTreeManager::itemDoubleClicked_FieldMonitor(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.last();

	// > 双击树节点
	QString id = last_item->data(0, Qt::UserRole).toString();
	QString class_name = last_item->data(0, Qt::UserRole + 1).toString();

	if (class_name == "C_FieldMonitor") {
		S_MonitorWindowManager::getInstance()->openModifyWindowFieldMonitor(id);
	}
}
/*-----------------------------------
		树节点事件（场监视器） - 右键操作
*/
void S_MonitorTreeManager::itemRightClicked_FieldMonitor(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.last();

    // 存储全部id而不是最后一个 2025-6-30 杨骁
    QStringList dataIdList;
    for (auto tmpItem : item_list)
    {
        dataIdList.append(tmpItem->data(0, Qt::UserRole).toString());
    }

	// > 右键树根
	if (this->m_root_FieldMonitor == last_item) {
		QMenu *popMenu = new QMenu();

		QAction *action;

		action = new QAction(tr("Add Field Monitor"), this);
		// action->setIcon(QIcon(":/sim" + QRC_IconPath + "/sim/FieldMonitor.png"));
		connect(action, &QAction::triggered, S_MonitorWindowManager::getInstance(), &S_MonitorWindowManager::openAddWindowFieldMonitor);
		popMenu->addAction(action);

		popMenu->addSeparator();

		action = new QAction(tr("Expand All"), this);
		connect(action, &QAction::triggered, this, &S_MonitorTreeManager::setRootExpandAll_FieldMonitor);
		if (this->m_root_FieldMonitor->childCount() == 0) { action->setDisabled(true); }
		popMenu->addAction(action);

		action = new QAction(tr("Collapse All"), this);
		connect(action, &QAction::triggered, this, &S_MonitorTreeManager::setRootCollapseAll_FieldMonitor);
		if (this->m_root_FieldMonitor->childCount() == 0) { action->setDisabled(true); }
		popMenu->addAction(action);

		// 从鼠标位置展开右键菜单
		popMenu->exec(QCursor::pos());
		return;
	}


	// > 右键树节点
	QString id = last_item->data(0, Qt::UserRole).toString();
	QString class_name = last_item->data(0, Qt::UserRole + 1).toString();

	if (class_name == "C_FieldMonitor") {
		QMenu *popMenu = new QMenu();

		QAction *action;

		action = new QAction(tr("Edit Field Monitor"), this);
		// action->setIcon(QIcon(":/others" + QRC_IconPath + "/others/Edit.png"));
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorWindowManager::getInstance(), &S_MonitorWindowManager::openModifyWindowFieldMonitorInAction);
		popMenu->addAction(action);

		action = new QAction(tr("Copy Field Monitor"), this);
		// action->setIcon(QIcon(":/others" + QRC_IconPath + "/others/Copy.png"));
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::copyByAction);
		popMenu->addAction(action);

		action = new QAction(tr("Delete Field Monitor"), this);
		// action->setIcon(QIcon(":/others" + QRC_IconPath + "/others/Delete.png"));
		// action->setData(id);
        action->setData(QVariant::fromValue(dataIdList));
		connect(action, &QAction::triggered, S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::deleteByAction);
		popMenu->addAction(action);

		popMenu->exec(QCursor::pos());
	}
}




/*-----------------------------------
		树根（场强探头） - 树根初始化
*/
void S_MonitorTreeManager::initRoot_Probes(QTreeWidget* treeWidget) {

	// > 树根设置
	this->m_root_Probes = new QTreeWidgetItem(treeWidget);
	this->m_root_Probes->setText(0, tr("Probes"));
	this->m_root_Probes->setIcon(0, QIcon(":/others" + QRC_IconPath + "/others/DirSource.png"));
	this->m_root_Probes->setExpanded(false);
	treeWidget->insertTopLevelItem(0, this->m_root_Probes);

	// > 参数初始化
	this->m_selectedList_ProbesId.clear();
}
/*-----------------------------------
		树根（场强探头） - 获取
*/
QTreeWidgetItem* S_MonitorTreeManager::getRoot_Probes() {
	return this->m_root_Probes;
}
/*-----------------------------------
		树根（场强探头） - 刷新树根
*/
void S_MonitorTreeManager::refreshRoot_Probes() {
	this->clearRoot_Probes();

	// > 树根
	this->m_root_Probes->setText(0, tr("Probes"));

	// > 树节点
	QList<C_FieldProbe> port_list = S_MonitorDataContainer::getInstance()->getDataFieldProbeList();
	for (int i = 0; i < port_list.count(); i++) {
		C_FieldProbe port = port_list.at(i);
		QTreeWidgetItem* item = new QTreeWidgetItem(this->m_root_Probes);
		item->setData(0, Qt::UserRole, port.getId());					//（放置ID）
		item->setData(0, Qt::UserRole + 1, port.get__CLASS_NAME__());	//（放置数据类型）
		item->setText(0, port.getName());
		item->setIcon(0, this->getIcon_Probes(S_MonitorDisplayingManager::getInstance()->isVisible_Probe(port.getId())));
		this->m_item_Probes.append(item);
	}

	emit signal_rootRefreshed_Probes();
}

/*-----------------------------------
		树根（场强探头） - 清空树根
*/
void S_MonitorTreeManager::clearRoot_Probes() {
	//（目前树根下没有 重要树枝，直接全清）

	this->clearBranch_Probes();
}
/*-----------------------------------
		树根（场强探头） - 清空树枝
*/
void S_MonitorTreeManager::clearBranch_Probes() {
	this->m_root_Probes->takeChildren();
	this->m_item_Probes.clear();
}
/*-----------------------------------
		树根（场强探头） - 展开/折叠树根
*/
void S_MonitorTreeManager::setRootExpandAll_Probes() {
	P_TreeItemExpender p;
	p.expandAll(this->m_root_Probes);
}
void S_MonitorTreeManager::setRootCollapseAll_Probes() {
	P_TreeItemExpender p;
	p.collapseAll(this->m_root_Probes);
}

/*-----------------------------------
		树节点事件（场强探头） - 失去焦点时
*/
void S_MonitorTreeManager::itemFocusOut_Probes(QList<QTreeWidgetItem*> item_list) {
	// > 清空白框描述
	//	（在 S_SoftwareAreaTreeManager 中控制，此处不管）

	// > 选中 - 清空
	this->m_selectedList_ProbesId.clear();
	emit signal_itemSelectChanged_Probes();

	// > 显示 - 刷新显示
	S_MonitorDisplayingManager::getInstance()->refreshVisible_ProbeAll();
}
/*-----------------------------------
		树节点事件（场强探头） - 单击操作
*/
void S_MonitorTreeManager::itemClicked_Probes(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.first();

	//（无）
}
/*-----------------------------------
		树节点事件（场强探头） - 改变操作
*/
void S_MonitorTreeManager::itemSelectionChanged_Probes(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.last();

	// > 单击树根
	if (this->m_root_Probes == last_item){

		// > 选中 - 清空
		this->m_selectedList_ProbesId.clear();
		emit signal_itemSelectChanged_Probes();

		// > 显示 - 刷新显示
		S_MonitorDisplayingManager::getInstance()->refreshVisible_ProbeAll();

		// > 白色参数块
		S_FloatingTextBlock::getInstance()->hideBlock();

		return;
	}

	QString id = last_item->data(0, Qt::UserRole).toString();
	QString class_name = last_item->data(0, Qt::UserRole + 1).toString();
	if (class_name == "C_FieldProbe"){

		// > 单击节点
		if (item_list.count() == 1){

			// > 选中 - 单选
			this->m_selectedList_ProbesId.clear();
			this->m_selectedList_ProbesId.append(id);
			emit signal_itemSelectChanged_Probes();
			
			// > 显示 - 模型全部透明
			S_ModelingPre_InteractiveManager::getInstance()->model_setTransparentAll(true, false);

			// > 显示 - 刷新显示
			S_MonitorDisplayingManager::getInstance()->refreshVisible_ProbeAll();

			// > 白色参数块
			C_FieldProbe c_data = S_MonitorDataContainer::getInstance()->getDataFieldProbeById(id);
			if (c_data.isNull()){
				S_FloatingTextBlock::getInstance()->hideBlock();
				return;
			}
			S_FloatingTextBlock::getInstance()->setText(c_data.getName(), c_data.getAttributesDesc());
			S_FloatingTextBlock::getInstance()->showBlock();

		// > 多选节点时
		}else{

			// > 选中 - 多选
			QStringList id_list;
			for (QTreeWidgetItem* item : item_list) {
				id_list.append(item->data(0, Qt::UserRole).toString());
			}
			this->m_selectedList_ProbesId = id_list;
			emit signal_itemSelectChanged_Probes();

			// > 显示 - 模型全部透明
			S_ModelingPre_InteractiveManager::getInstance()->model_setTransparentAll(true, false);

			// > 显示 - 刷新显示
			S_MonitorDisplayingManager::getInstance()->refreshVisible_ProbeAll();

			// > 白色参数块
			S_FloatingTextBlock::getInstance()->hideBlock();
		}
	}
}
/*-----------------------------------
		树节点事件（场强探头） - 双击操作
*/
void S_MonitorTreeManager::itemDoubleClicked_Probes(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.last();

	// > 双击树节点
	QString id = last_item->data(0, Qt::UserRole).toString();
	QString class_name = last_item->data(0, Qt::UserRole + 1).toString();

	if (class_name == "C_FieldProbe") {
		S_MonitorWindowManager::getInstance()->openModifyWindowFieldProbe(id);
	}
}
/*-----------------------------------
		树节点事件（场强探头） - 右键操作
*/
void S_MonitorTreeManager::itemRightClicked_Probes(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.last();

	// > 右键树根
	if (this->m_root_Probes == last_item) {
		QMenu *popMenu = new QMenu();

		QAction *action;

		action = new QAction(tr("添加场强探头"), this);
		// action->setIcon(QIcon(":/sim" + QRC_IconPath +"/sim/FieldProbe.png"));
		connect(action, &QAction::triggered, S_MonitorWindowManager::getInstance(), &S_MonitorWindowManager::openAddWindowFieldProbe);
		popMenu->addAction(action);

		popMenu->addSeparator();

		// action = new QAction(tr("隐藏全部"), this);
		// connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_hideAll_FieldProbe);
		// popMenu->addAction(action);

		// action = new QAction(tr("显示全部"), this);
		// connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_showAll_FieldProbe);
		// popMenu->addAction(action);

		// popMenu->addSeparator();

		action = new QAction(tr("展开全部"), this);
		connect(action, &QAction::triggered, this, &S_MonitorTreeManager::setRootExpandAll_Probes);
		if (this->m_root_Probes->childCount() == 0) { action->setDisabled(true); }
		popMenu->addAction(action);

		action = new QAction(tr("折叠全部"), this);
		connect(action, &QAction::triggered, this, &S_MonitorTreeManager::setRootCollapseAll_Probes);
		if (this->m_root_Probes->childCount() == 0) { action->setDisabled(true); }
		popMenu->addAction(action);

		// 从鼠标位置展开右键菜单
		popMenu->exec(QCursor::pos());
		return;
	}


	// > 右键树节点
	QString id = last_item->data(0, Qt::UserRole).toString();
	QString class_name = last_item->data(0, Qt::UserRole + 1).toString();

	if (class_name == "C_FieldProbe") {
		QMenu *popMenu = new QMenu();

		QAction *action;

		action = new QAction(tr("隐藏"), this);
		// action->setIcon(QIcon(":/view" + QRC_IconPath + "/view/Hide.png"));
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_hide_Probe);
		popMenu->addAction(action);

		action = new QAction(tr("显示"), this);
		// action->setIcon(QIcon(":/view" + QRC_IconPath + "/view/Show.png"));
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_show_Probe);
		popMenu->addAction(action);

		action = new QAction(tr("隐藏全部"), this);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_hideAll_Probe);
		popMenu->addAction(action);

		action = new QAction(tr("显示全部"), this);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_showAll_Probe);
		popMenu->addAction(action);

		popMenu->addSeparator();

		action = new QAction(tr("编辑场强探头"), this);
		// action->setIcon(QIcon(":/others" + QRC_IconPath + "/others/Edit.png"));
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorWindowManager::getInstance(), &S_MonitorWindowManager::openModifyWindowFieldProbeInAction);
		popMenu->addAction(action);

		action = new QAction(tr("复制场强探头"), this);
		// action->setIcon(QIcon(":/others" + QRC_IconPath + "/others/Copy.png"));
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::copyByAction);
		popMenu->addAction(action);

		action = new QAction(tr("删除场强探头"), this);
		// action->setIcon(QIcon(":/others" + QRC_IconPath + "/others/Delete.png"));
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::deleteByAction);
		popMenu->addAction(action);

		popMenu->exec(QCursor::pos());
	}
}

/*-------------------------------------------------
		树节点（场强探头） - 获取树节点
*/
QTreeWidgetItem* S_MonitorTreeManager::getItem_ProbesById(QString data_id){
	for (int i = 0; i < this->m_item_Probes.count(); i++){
		QTreeWidgetItem *item = this->m_item_Probes.at(i);
		QString id = item->data(0, Qt::UserRole).toString();
		if (id == data_id){
			return item;
		}
	}
	return nullptr;
}
/*-------------------------------------------------
		树节点（场强探头） - 是否有选中ID
*/
bool S_MonitorTreeManager::hasItemSelectedID_Probes(){
	return this->m_selectedList_ProbesId.count() > 0;
}
/*-------------------------------------------------
		树节点（场强探头） - 获取选中ID
*/
QStringList S_MonitorTreeManager::getItemSelectedID_Probes(){
	return this->m_selectedList_ProbesId;
}

/*-------------------------------------------------
		树节点（场强探头） - 显示数据变化时
*/
void S_MonitorTreeManager::visibleChanged_Probes(QString data_id, bool visible) {
	QTreeWidgetItem* item = this->getItem_ProbesById(data_id);
	item->setIcon(0, this->getIcon_Probes(visible));
}
/*-----------------------------------
		树节点（场强探头） - 获取图标
*/
QIcon S_MonitorTreeManager::getIcon_Probes(bool visible) {
	// > 原图标
	if (visible == true) {
		return S_IconOpacityManager::getInstance()->getIcon(":/sim" + QRC_IconPath +"/sim/FieldProbe.png", 255);
		
	// > 半透明图标
	}else {
		return S_IconOpacityManager::getInstance()->getIcon(":/sim" + QRC_IconPath +"/sim/FieldProbe.png", 100);
	}
}




/*-----------------------------------
		树根（电压和电流监视器） - 树根初始化
*/
void S_MonitorTreeManager::initRoot_VAndCMonitor(QTreeWidget* treeWidget) {

	// > 树根设置
	this->m_root_VAndCMonitor = new QTreeWidgetItem(treeWidget);
	this->m_root_VAndCMonitor->setText(0, tr("Voltage and Current Monitors"));
	this->m_root_VAndCMonitor->setIcon(0, QIcon(":/others" + QRC_IconPath + "/others/DirSource.png"));
	this->m_root_VAndCMonitor->setExpanded(false);
	treeWidget->insertTopLevelItem(0, this->m_root_VAndCMonitor);

	// > 参数初始化
	this->m_selectedList_CurrentId.clear();
	this->m_selectedList_VoltageId.clear();
}
/*-----------------------------------
		树根（电压和电流监视器） - 获取
*/
QTreeWidgetItem* S_MonitorTreeManager::getRoot_VAndCMonitor() {
	return this->m_root_VAndCMonitor;
}
/*-----------------------------------
		树根（电压和电流监视器） - 刷新树根
*/
void S_MonitorTreeManager::refreshRoot_VAndCMonitor() {
	this->clearRoot_VAndCMonitor();

	// > 树根
	this->m_root_VAndCMonitor->setText(0, tr("Voltage and Current Monitors"));

	// > 树节点 - 电压监视器
	QList<C_VoltageMonitor> voltage_list = S_MonitorDataContainer::getInstance()->getDataVoltageMonitorList();
	for (int i = 0; i < voltage_list.count(); i++) {
		C_VoltageMonitor voltage = voltage_list.at(i);
		QTreeWidgetItem* item = new QTreeWidgetItem(this->m_root_VAndCMonitor);
		item->setData(0, Qt::UserRole, voltage.getId());				//（放置ID）
		item->setData(0, Qt::UserRole+1, voltage.get__CLASS_NAME__());	//（放置数据类型）
		item->setText(0, voltage.getName());
		item->setIcon(0,this->getIcon_VoltageMonitor(S_MonitorDisplayingManager::getInstance()->isVisible_VoltageMonitor(voltage.getId())));
		this->m_item_VoltageMonitor.append(item);
	}

	// > 树节点 - 电流监视器
	QList<C_CurrentMonitor> current_list = S_MonitorDataContainer::getInstance()->getDataCurrentMonitorList();
	for (int i = 0; i < current_list.count(); i++) {
		C_CurrentMonitor current = current_list.at(i);
		QTreeWidgetItem* item = new QTreeWidgetItem(this->m_root_VAndCMonitor);
		item->setData(0, Qt::UserRole, current.getId());					//（放置ID）
		item->setData(0, Qt::UserRole + 1, current.get__CLASS_NAME__());	//（放置数据类型）
		item->setText(0, current.getName());
		item->setIcon(0, this->getIcon_CurrentMonitor(S_MonitorDisplayingManager::getInstance()->isVisible_CurrentMonitor(current.getId())));
		this->m_item_CurrentMonitor.append(item);
	}

	emit signal_rootRefreshed_VAndCMonitor();
}

/*-----------------------------------
		树根（电压和电流监视器） - 清空树根
*/
void S_MonitorTreeManager::clearRoot_VAndCMonitor() {
	//（目前树根下没有 重要树枝，直接全清）

	this->clearBranch_VAndCMonitor();
}
/*-----------------------------------
		树根（电压和电流监视器） - 清空树枝
*/
void S_MonitorTreeManager::clearBranch_VAndCMonitor() {
	this->m_root_VAndCMonitor->takeChildren();
	this->m_item_VoltageMonitor.clear();
	this->m_item_CurrentMonitor.clear();
}
/*-----------------------------------
		树根（电压和电流监视器） - 展开/折叠树根
*/
void S_MonitorTreeManager::setRootExpandAll_VAndCMonitor() {
	P_TreeItemExpender p;
	p.expandAll(this->m_root_VAndCMonitor);
}
void S_MonitorTreeManager::setRootCollapseAll_VAndCMonitor() {
	P_TreeItemExpender p;
	p.collapseAll(this->m_root_VAndCMonitor);
}

/*-----------------------------------
		树节点事件（电压和电流监视器） - 失去焦点时
*/
void S_MonitorTreeManager::itemFocusOut_VAndCMonitor(QList<QTreeWidgetItem*> item_list) {
	// > 清空白框描述
	//	（在 S_SoftwareAreaTreeManager 中控制，此处不管）

	// > 选中 - 清空
	this->m_selectedList_CurrentId.clear();
	this->m_selectedList_VoltageId.clear();
	emit signal_itemSelectChanged_CurrentMonitor();
	emit signal_itemSelectChanged_VoltageMonitor();

	// > 显示 - 刷新显示
	S_MonitorDisplayingManager::getInstance()->refreshVisible_CurrentMonitorAll();
	S_MonitorDisplayingManager::getInstance()->refreshVisible_VoltageMonitorAll();
}
/*-----------------------------------
		树节点事件（电压和电流监视器） - 单击操作
*/
void S_MonitorTreeManager::itemClicked_VAndCMonitor(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.first();

	//（无）
}
/*-----------------------------------
		树节点事件（电压和电流监视器） - 改变操作
*/
void S_MonitorTreeManager::itemSelectionChanged_VAndCMonitor(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.last();

	// > 单击树根
	if (this->m_root_VAndCMonitor == last_item) {

		// > 选中 - 清空
		this->m_selectedList_CurrentId.clear();
		this->m_selectedList_VoltageId.clear();
		emit signal_itemSelectChanged_CurrentMonitor();
		emit signal_itemSelectChanged_VoltageMonitor();

		// > 显示 - 刷新显示
		S_MonitorDisplayingManager::getInstance()->refreshVisible_CurrentMonitorAll();
		S_MonitorDisplayingManager::getInstance()->refreshVisible_VoltageMonitorAll();

		// > 白色参数块
		S_FloatingTextBlock::getInstance()->hideBlock();

		return;
	}

	QString id = last_item->data(0, Qt::UserRole).toString();
	QString class_name = last_item->data(0, Qt::UserRole + 1).toString();

	// > 单击节点
	if (item_list.count() == 1) {
		if (class_name == "C_CurrentMonitor") {

			// > 选中 - 单选
			this->m_selectedList_CurrentId.clear();
			this->m_selectedList_CurrentId.append(id);
			emit signal_itemSelectChanged_CurrentMonitor();

			// > 显示 - 模型全部透明
			S_ModelingPre_InteractiveManager::getInstance()->model_setTransparentAll(true, false);

			// > 显示 - 刷新显示
			S_MonitorDisplayingManager::getInstance()->refreshVisible_CurrentMonitorAll();

			// > 白色参数块
			C_CurrentMonitor c_data = S_MonitorDataContainer::getInstance()->getDataCurrentMonitorById(id);
			if (c_data.isNull()) {
				S_FloatingTextBlock::getInstance()->hideBlock();
				return;
			}
			S_FloatingTextBlock::getInstance()->setText(c_data.getName(), c_data.getAttributesDesc());
			S_FloatingTextBlock::getInstance()->showBlock();
		}
		if (class_name == "C_VoltageMonitor") {

			// > 选中 - 单选
			this->m_selectedList_VoltageId.clear();
			this->m_selectedList_VoltageId.append(id);
			emit signal_itemSelectChanged_VoltageMonitor();

			// > 显示 - 模型全部透明
			S_ModelingPre_InteractiveManager::getInstance()->model_setTransparentAll(true, false);

			// > 显示 - 刷新显示
			S_MonitorDisplayingManager::getInstance()->refreshVisible_VoltageMonitorAll();

			// > 白色参数块
			C_VoltageMonitor c_data = S_MonitorDataContainer::getInstance()->getDataVoltageMonitorById(id);
			if (c_data.isNull()) {
				S_FloatingTextBlock::getInstance()->hideBlock();
				return;
			}
			S_FloatingTextBlock::getInstance()->setText(c_data.getName(), c_data.getAttributesDesc());
			S_FloatingTextBlock::getInstance()->showBlock();
		}
		
	// > 多选节点时
	}else{

		// > 选中 - 多选
		QStringList voltageMonitor_id_list;
		QStringList currentMonitor_id_list;
		for (int i = 0; i < item_list.count(); i++) {
			QTreeWidgetItem* item = item_list.at(i);
			if (this->m_item_VoltageMonitor.contains(item)) {
				voltageMonitor_id_list.append(item->data(0, Qt::UserRole).toString());
			}
			if (this->m_item_CurrentMonitor.contains(item)) {
				currentMonitor_id_list.append(item->data(0, Qt::UserRole).toString());
			}
		}
		this->m_selectedList_VoltageId = voltageMonitor_id_list;
		this->m_selectedList_CurrentId = currentMonitor_id_list;
		emit signal_itemSelectChanged_CurrentMonitor();
		emit signal_itemSelectChanged_VoltageMonitor();

		// > 显示 - 模型全部透明
		S_ModelingPre_InteractiveManager::getInstance()->model_setTransparentAll(true, false);

		// > 显示 - 刷新显示
		S_MonitorDisplayingManager::getInstance()->refreshVisible_CurrentMonitorAll();
		S_MonitorDisplayingManager::getInstance()->refreshVisible_VoltageMonitorAll();

		// > 白色参数块
		S_FloatingTextBlock::getInstance()->hideBlock();
	}
}
/*-----------------------------------
		树节点事件（电压和电流监视器） - 双击操作
*/
void S_MonitorTreeManager::itemDoubleClicked_VAndCMonitor(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.last();

	// > 双击树节点
	QString id = last_item->data(0, Qt::UserRole).toString();
	QString class_name = last_item->data(0, Qt::UserRole + 1).toString();

	if (class_name == "C_VoltageMonitor") {
		S_MonitorWindowManager::getInstance()->openModifyWindowVoltageMonitor(id);
	}
	if (class_name == "C_CurrentMonitor") {
		S_MonitorWindowManager::getInstance()->openModifyWindowCurrentMonitor(id);
	}
}
/*-----------------------------------
		树节点事件（电压和电流监视器） - 右键操作
*/
void S_MonitorTreeManager::itemRightClicked_VAndCMonitor(QList<QTreeWidgetItem*> item_list) {
	if (item_list.count() == 0) { return; }
	QTreeWidgetItem* last_item = item_list.last();

	// > 右键树根
	if (this->m_root_VAndCMonitor == last_item) {
		QMenu *popMenu = new QMenu();
		QAction *action;

		action = new QAction(tr("New Voltage Monitor..."), this);
		connect(action, &QAction::triggered, S_MonitorWindowManager::getInstance(), &S_MonitorWindowManager::openAddWindowVoltageMonitor);
		popMenu->addAction(action);

		action = new QAction(tr("New Current Monitor..."), this);
		connect(action, &QAction::triggered, S_MonitorWindowManager::getInstance(), &S_MonitorWindowManager::openAddWindowCurrentMonitor);
		popMenu->addAction(action);

		popMenu->addSeparator();


		action = new QAction(tr("Hide All Voltage Monitors"), this);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_hideAll_VoltageMonitor);
		popMenu->addAction(action);

		action = new QAction(tr("Show All Voltage Monitors"), this);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_showAll_VoltageMonitor);
		popMenu->addAction(action);

		popMenu->addAction(new QAction(tr("Hide All Current Monitors")));//（未完）
		popMenu->addAction(new QAction(tr("Show All Current Monitors")));//（未完）
		popMenu->addAction(new QAction(tr("Show All")));//（未完）

		popMenu->addSeparator();

		action = new QAction(tr("展开全部"), this);
		connect(action, &QAction::triggered, this, &S_MonitorTreeManager::setRootExpandAll_VAndCMonitor);
		if (this->m_root_VAndCMonitor->childCount() == 0) { action->setDisabled(true); }
		popMenu->addAction(action);

		action = new QAction(tr("折叠全部"), this);
		connect(action, &QAction::triggered, this, &S_MonitorTreeManager::setRootCollapseAll_VAndCMonitor);
		if (this->m_root_VAndCMonitor->childCount() == 0) { action->setDisabled(true); }
		popMenu->addAction(action);

		popMenu->exec(QCursor::pos());

		return;
	}


	// > 右键树节点
	QString id = last_item->data(0, Qt::UserRole).toString();
	QString class_name = last_item->data(0, Qt::UserRole+1).toString();

	if (class_name == "C_VoltageMonitor") {
		QMenu *popMenu = new QMenu();
		QAction *action;

		action = new QAction(tr("隐藏"), this);
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_hide_VoltageMonitor);
		popMenu->addAction(action);

		action = new QAction(tr("显示"), this);
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_show_VoltageMonitor);
		popMenu->addAction(action);

		action = new QAction(tr("隐藏全部"), this);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_hideAll_VoltageMonitor);
		popMenu->addAction(action);

		action = new QAction(tr("显示全部"), this);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_showAll_VoltageMonitor);
		popMenu->addAction(action);

		popMenu->addSeparator();

		action = new QAction(tr("编辑电压监视器"), this);
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorWindowManager::getInstance(), &S_MonitorWindowManager::openModifyWindowVoltageMonitorInAction);
		popMenu->addAction(action);

		action = new QAction(tr("复制电压监视器"), this);
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::copyByAction);
		popMenu->addAction(action);

		action = new QAction(tr("删除电压监视器"), this);
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::deleteByAction);
		popMenu->addAction(action);

		popMenu->exec(QCursor::pos());
	}
	if (class_name == "C_CurrentMonitor") {
		QMenu* popMenu = new QMenu();
		QAction* action;

		action = new QAction(tr("隐藏"), this);
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_hide_CurrentMonitor);
		popMenu->addAction(action);

		action = new QAction(tr("显示"), this);
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_show_CurrentMonitor);
		popMenu->addAction(action);

		action = new QAction(tr("隐藏全部"), this);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_hideAll_CurrentMonitor);
		popMenu->addAction(action);

		action = new QAction(tr("显示全部"), this);
		connect(action, &QAction::triggered, S_MonitorDisplayingManager::getInstance(), &S_MonitorDisplayingManager::action_showAll_CurrentMonitor);
		popMenu->addAction(action);

		popMenu->addSeparator();

		action = new QAction(tr("编辑电流监视器"), this);
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorWindowManager::getInstance(), &S_MonitorWindowManager::openModifyWindowCurrentMonitorInAction);
		popMenu->addAction(action);

		action = new QAction(tr("复制电流监视器"), this);
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::copyByAction);
		popMenu->addAction(action);

		action = new QAction(tr("删除电流监视器"), this);
		action->setData(id);
		connect(action, &QAction::triggered, S_MonitorDataContainer::getInstance(), &S_MonitorDataContainer::deleteByAction);
		popMenu->addAction(action);

		popMenu->exec(QCursor::pos());
	}
}

/*-----------------------------------
		树节点（电压和电流监视器） - 获取树节点
*/
QTreeWidgetItem* S_MonitorTreeManager::getItem_VoltageMonitorById(QString data_id) {
	for (int i = 0; i < this->m_item_VoltageMonitor.count(); i++) {
		QTreeWidgetItem* item = this->m_item_VoltageMonitor.at(i);
		QString id = item->data(0, Qt::UserRole).toString();
		if (id == data_id) {
			return item;
		}
	}
	return nullptr;
}
QTreeWidgetItem* S_MonitorTreeManager::getItem_CurrentMonitorById(QString data_id) {
	for (int i = 0; i < this->m_item_CurrentMonitor.count(); i++) {
		QTreeWidgetItem* item = this->m_item_CurrentMonitor.at(i);
		QString id = item->data(0, Qt::UserRole).toString();
		if (id == data_id) {
			return item;
		}
	}
	return nullptr;
}
/*-----------------------------------
		树节点（电压和电流监视器） - 是否有选中ID
*/
bool S_MonitorTreeManager::hasItemSelectedID_VoltageMonitor() {
	return this->m_selectedList_VoltageId.count() > 0;
}
bool S_MonitorTreeManager::hasItemSelectedID_CurrentMonitor() {
	return this->m_selectedList_CurrentId.count() > 0;
}
/*-----------------------------------
		树节点（电压和电流监视器） - 获取选中ID
*/
QStringList S_MonitorTreeManager::getItemSelectedID_VoltageMonitor() {
	return this->m_selectedList_VoltageId;
}
QStringList S_MonitorTreeManager::getItemSelectedID_CurrentMonitor() {
	return this->m_selectedList_CurrentId;
}

/*-----------------------------------
		树节点（电压和电流监视器） - 显示数据变化时
*/
void S_MonitorTreeManager::visibleChanged_VoltageMonitor(QString data_id, bool visible) {
	QTreeWidgetItem* item = this->getItem_VoltageMonitorById(data_id);
	item->setIcon(0, this->getIcon_VoltageMonitor(visible));
}
void S_MonitorTreeManager::visibleChanged_CurrentMonitor(QString data_id, bool visible) {
	QTreeWidgetItem* item = this->getItem_CurrentMonitorById(data_id);
	item->setIcon(0, this->getIcon_CurrentMonitor(visible));
}
/*-----------------------------------
		树节点（电压和电流监视器） - 获取图标
*/
QIcon S_MonitorTreeManager::getIcon_VoltageMonitor(bool visible) {
	// > 原图标
	if (visible == true) {
		return S_IconOpacityManager::getInstance()->getIcon(":/sim" + QRC_IconPath + "/sim/VoltageMonitorLeft.png", 255);
		
	// > 半透明图标
	}else {
		return S_IconOpacityManager::getInstance()->getIcon(":/sim" + QRC_IconPath + "/sim/VoltageMonitorLeft.png", 100);
	}
}
QIcon S_MonitorTreeManager::getIcon_CurrentMonitor(bool visible) {
	// > 原图标
	if (visible == true) {
		return S_IconOpacityManager::getInstance()->getIcon(":/sim" + QRC_IconPath + "/sim/CurrentMonitorLeft.png", 255);
		
	// > 半透明图标
	}else {
		return S_IconOpacityManager::getInstance()->getIcon(":/sim" + QRC_IconPath + "/sim/CurrentMonitorLeft.png", 100);
	}
}




/*-----------------------------------
		数据容器 - 树变化 - 某数据 被添加
*/
void S_MonitorTreeManager::containerDataAdded(C_UndoDataBasePtr ptr, int index) {

	// > 场监视器
	if (ptr->get__CLASS_NAME__() == "C_FieldMonitor") {
		this->refreshRoot_FieldMonitor();
		this->setRootExpandAll_FieldMonitor();
		return;
	}

	// > 场强探头数据
	if (ptr->get__CLASS_NAME__() == "C_FieldProbe") {
		this->refreshRoot_Probes();
		this->setRootExpandAll_Probes();
		return;
	}

	// > 电压监视器
	if (ptr->get__CLASS_NAME__() == "C_VoltageMonitor") {
		this->refreshRoot_VAndCMonitor();
		this->setRootExpandAll_VAndCMonitor();
		return;
	}
	// > 电流监视器
	if (ptr->get__CLASS_NAME__() == "C_CurrentMonitor") {
		this->refreshRoot_VAndCMonitor();
		this->setRootExpandAll_VAndCMonitor();
		return;
	}
}
/*-----------------------------------
		数据容器 - 树变化 - 某数据 被修改
*/
void S_MonitorTreeManager::containerDataModifyed(C_UndoDataBasePtr ptr, int index) {

	// > 场监视器
	if (ptr->get__CLASS_NAME__() == "C_FieldMonitor") {
		this->refreshRoot_FieldMonitor();
		return;
	}

	// > 场强探头数据
	if (ptr->get__CLASS_NAME__() == "C_FieldProbe") {
		this->refreshRoot_Probes();
		return;
	}

	// > 电压监视器
	if (ptr->get__CLASS_NAME__() == "C_VoltageMonitor") {
		this->refreshRoot_VAndCMonitor();
		return;
	}
	// > 电流监视器
	if (ptr->get__CLASS_NAME__() == "C_CurrentMonitor") {
		this->refreshRoot_VAndCMonitor();
		return;
	}
}
/*-----------------------------------
		数据容器 - 树变化 - 某数据 被删除
*/
void S_MonitorTreeManager::containerDataDeleted(C_UndoDataBasePtr ptr, int index) {

	// > 场监视器
	if (ptr->get__CLASS_NAME__() == "C_FieldMonitor") {
		this->refreshRoot_FieldMonitor();
		return;
	}

	// > 场强探头数据
	if (ptr->get__CLASS_NAME__() == "C_FieldProbe") {
		this->refreshRoot_Probes();
		return;
	}

	// > 电压监视器
	if (ptr->get__CLASS_NAME__() == "C_VoltageMonitor") {
		this->refreshRoot_VAndCMonitor();
		return;
	}
	// > 电流监视器
	if (ptr->get__CLASS_NAME__() == "C_CurrentMonitor") {
		this->refreshRoot_VAndCMonitor();
		return;
	}
}
/*-----------------------------------
		数据容器 - 树变化 - 某全局数据 被修改
*/
void S_MonitorTreeManager::containerGlobalDataModifyed(C_UndoDataGlobalBasePtr ptr) {
	this->refreshRoot_FieldMonitor();
	this->refreshRoot_Probes();

	this->setRootExpandAll_FieldMonitor();
	this->setRootExpandAll_Probes();
}
/*-----------------------------------
		数据容器 - 树变化 - 存储数据 被读取
*/
void S_MonitorTreeManager::containerDataAllReloaded() {

	// > 场监视器
	this->refreshRoot_FieldMonitor();

	// > 场强探头数据
	this->refreshRoot_Probes();

	// > 电压监视器 + 电流监视器
	this->refreshRoot_VAndCMonitor();
}



